'use strict';
const Service = require('egg').Service;
function getdayString(date) {
  if (!date) {
    date = new Date();
  }
  return `${date.getFullYear()}${(date.getMonth() + 1 + '').padStart(2, '0')}${(date.getDate() + '').padStart(2, '0')}`;
}
function getTomorrow() {
  return new Date(+new Date() + 24 * 60 * 60 * 1000);
}
class IsWorkDayService extends Service {
  async index() {
    const { ctx } = this;
    const url = `http://tool.bitefu.net/jiari/?d=${getdayString() + ',' + getdayString(getTomorrow())}`;
    console.log(url);
    const res = await ctx.curl(url, {
      method: 'GET',
      dataType: 'json',
    });
    let data = {
      today: 1,
      nextDay: 1,
    };
    const temp = Object.values(res.data);
    if (temp.length) {
      data = {
        today: temp[0],
        nextDay: temp[1],
      };
    }
    return data;
  }
}

module.exports = IsWorkDayService;
